package exercicios.ex02.view;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class Tabuada
 */
@WebServlet("/tabuada")
public class Tabuada extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Tabuada() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter out = response.getWriter();
		response.setContentType("text/html;charset=utf-8");
		out.println("<html>\n"+
				"<head>\n"+
				"<meta charset=\"utf-8\">\n"+
				"<title>Tabuada de 1 a 9</title>\n"+
				"</head>\n"+
				"<body>\n");
		for (int i = 1; i <= 9; i++) {
			out.println("<table width=\"30%\" border=\"1\">");
			out.println("<th colspan=\"5\" align=\"center\">Tabuada de "+ i +"</th>");
			for (int j = 1; j <= 10; j++) {
				out.println("<tr align=\"center\"><td>"+i+"</td><td>X</td><td>"+j+"</td><td>=</td><td>"+(i*j)+"</td></tr>");
			}
			out.println("</table><p/>");
		}
		out.println("</body>\n"+
					"</html>");
		out.close();
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
